package com.xframe.xdal.core.autofill.proc;

import com.xframe.xdal.core.autofill.IAutoFillBean;
import com.xframe.xdal.core.autofill.IAutoProc;
import com.xframe.xdal.core.autofill.specification.ICacheKeyGenerate;
import com.xframe.xdal.core.util.redis.RedisAccess;
import lombok.extern.log4j.Log4j2;

/**
 * @Description: 自动生成资源权限值
 * @ClassName:  2 4 8 16 32 64 128
 * @Author: xufeng
 * @CreateTime: 2023/6/15
 **/
@Log4j2
public class RoleValCreateProc implements IAutoProc {
    @Override
    public Object getVal(IAutoFillBean autoFillBean, Object entity, Object val) {
        String key = "";
        if(entity instanceof ICacheKeyGenerate) {
            key = ((ICacheKeyGenerate) entity).getCacheKey();
        }else {
            key = autoFillBean.getArgs();
        }
        Long bit = RedisAccess.getSetCmd().incrBy(key,1);
        bit = bit - 1L;
        if(bit > 60L){
            bit = 0L;
            RedisAccess.getSetCmd().set(key,"0");
        }
        return 2L << bit;
    }
}
